﻿using System;
using System.Collections.Generic;
using System.Linq;
using LBoL.Base;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Battle.Interactions;
using LBoL.Core.Cards;
using LBoLEntitySideloader.Attributes;
using ProbeMod.Cards.Template;

namespace ProbeMod.Cards
{
    public sealed class ProbePulsarBeamDef : ProbeCardTemplate
    {
        public override CardConfig MakeConfig()
        {
            var config = GetCardDefaultConfig();

            config.Rarity = Rarity.Common;
            config.Type = CardType.Attack;
            config.TargetType = TargetType.SingleEnemy;
            config.Colors = new List<ManaColor>() { ManaColor.White };

            config.Cost = new ManaGroup() { White = 2,Any = 1 };
            
            config.Damage = 6;
            config.UpgradedDamage = 8;

            config.Value1 = 6;

            config.UpgradedKeywords = Keyword.Accuracy;

            config.Index = CardIndexGenerator.GetUniqueIndex(config);
            return config;
        }
    }

    /// <summary>
    /// 六脉神剑
    /// 造成6点伤害6次。如果目标具有护盾/格挡，伤害减半
    /// </summary>
    [EntityLogic(typeof(ProbePulsarBeamDef))]
    public sealed class ProbePulsarBeam : ProbeCard
    {
        protected override IEnumerable<BattleAction> Actions(UnitSelector selector, ManaGroup consumingMana, Interaction precondition)
        {
            if (selector.GetEnemy(Battle).Block > 0 || selector.GetEnemy(Battle).Shield > 0)
            {
                for (int i = 0; i < Value1; i++)
                {
                    yield return new DamageAction(Battle.Player, selector.GetEnemy(Battle), DamageInfo.Attack(Damage.Damage / 2, Damage.IsAccuracy));
                }
            }
            else
                for (int i = 0; i < Value1; i++)
                {
                    yield return AttackAction(selector);
                }

        }
    }
}
